https://cypress.io logo
was trying to swap out manual login to auth 0 with...
# e2e-testing
u
was trying to swap out manual login to auth 0 with something that will do it automatically but I can't seem to find out what belongs in this callback?code=state=
Copy code
Cypress.Commands.add('login', (email, password, overrides = {}) => {
  Cypress.log({
    name: 'loginViaAuth0',
  });
  const options = {
    method: 'POST',
    url: Cypress.env('auth_url'),
    body: {
      grant_type: 'password',
      username: email,
      password: password,
      audience: Cypress.env('auth_audience'),
      scope: 'openid profile email',
      client_id: Cypress.env('auth_client_id'),
      client_secret: Cypress.env('auth_client_secret'),
    },
  };
  cy.request(options)
    .then((resp) => {
      return resp.body;
    })
    .then((body) => {
      const { access_token, id_token } = body;
      const auth0State = {
        nonce: '',
        state: id_token
      };
      cy.visit(`/callback?code=${auth0State.state}state=${access_token}`,{
        onBeforeLoad(win) {
          win.document.cookie = 'auth0.is.authenticated', 'true';
          win.document.cookie = '_legacy_auth0.is.authenticated', 'true';

        }
      }).as('login');
    })
    cy.wait('@login'. {timeout: 60000});
});